import { Post, Get } from '@/utils/request.ts'
import type { CreateUserDto } from '@/api/user.api.ts'

export interface LoginUserDto {
  account: string

  password: string

  captchaId: string // 新增：验证码 ID

  captchaCode: string // 新增：验证码值
}

export interface LoginResultDto {
  message: string,
  access_token: string,
  refresh_token: string,
  user: {
    account: string;
    id: number;
    avatar: string;
  },
}

export const loginApi = (data: LoginUserDto) => {
  return Post<LoginUserDto, LoginResultDto>('/blog/auth/login', data)
}

export const getCaptchaApi = () => {
  return Get(`/blog/auth/captcha`)
}

export const getPermissionsApi = () => {
  return Get(`/blog/auth/permissions`)
}

export const logoutApi = (data: Record<string, string | undefined>) => {
  return Post<Record<string, string | undefined>, never>('/blog/auth/logout', data)
}

export const userRegisterApi = (data: CreateUserDto) =>{
  return Post<CreateUserDto, never>('/blog/auth/register', data)
}
